<?php

namespace App\Http\Controllers\Home;

use App\Http\Requests\UserRequest;
use App\User;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class UserController extends Controller
{
    public function __construct()
    {
        $this->middleware('guest',['only'=>['create','store']]);

    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //注册页面
       return view('home.user.creat');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    //注册方法

    public function store(UserRequest $request)
    {
if (filter_var($request->account,FILTER_VALIDATE_EMAIL)){
    $data['email']=$request->account;
    $dat['email_valid']=true;
}else{
    $data['phone']=$request->account;

    $dat['mobile_valid']=true;
}
$data['name']=$request->name;
$data['password']=bcrypt($request->password);
//dump($data);die;
User::create($data);
return redirect(route('home.login.login'))->with('success','注册成功');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, User $user)
    {

    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
    function attentions(User $user){
//        dd($user->toArray());
//        auth()->user()->
      auth()->user()->follwed()->toggle([$user->id]);
        return back();
    }
}
